package com.example.shop_2302.address

import androidx.lifecycle.viewModelScope
import com.example.base.entity.AddAddressEntity
import com.example.base.entity.Res
import com.example.base.mvvm.BaseViewModel
import com.example.base.param.ParamAddAddress
import com.example.shop_2302.utils.SingleLiveData
import kotlinx.coroutines.launch

class AddressViewModel :BaseViewModel(){
    //返回值---添加地址
    val addSuccess = SingleLiveData<Res<AddAddressEntity>>()
    val addFail = SingleLiveData<String>()
    fun addAddress(paramAddAddress: ParamAddAddress){
        viewModelScope.launch {
            try {
                addSuccess.postValue(apiServer.addAddress(paramAddAddress))
            }catch (e:Exception){
                addFail.postValue(e.message.toString())
            }
        }
    }
}